#   根据master文件，与slave文件的每行相比较，根据nan数据的多少，找出需要补全的行
#   此程序要求两个文件行数相等且顺序相同, 标题行为第一行

from ExcelClass import Sheet

def main():
    path = './data_source/'
    slave_filename = 'panda_read_excel--1.xlsx'
    slave_excel = Sheet(path, slave_filename, sheet='Sheet2')
    master_filename = 'panda_read_excel.xlsx'
    master_excel = Sheet(path, master_filename, sheet='Sheet2')
    # get master file's row num
    master_row_num = master_excel.get_col_num()
    print('row_num:', master_excel.get_col_num())
    # traverse each row and compare nan values
    key_line_num = 0 # 标题行所在行数
    try:
        for i,row in enumerate(range(master_row_num)) :
            master_line_content = master_excel.get_line(row)
            slave_line_content = slave_excel.get_line(row)
            # print(f'i:{i}, {master_excel.get_nan_count_by_line(i)} <{slave_excel.get_nan_count_by_line(i)}' )

            if master_excel.get_nan_count_by_line(i) > slave_excel.get_nan_count_by_line(i):
                # 如果主文件当前行的空白单元格相比更多
                # print(f'need to recover on serial: {master_excel.get_serial_nums()}')
                print(f'need to recover on serial: {master_line_content[0]},{master_line_content[2]}')
                # 将符合条件从文件的行覆盖主文件， i+1是为了跳过标题行
                master_excel.cover_line(i + key_line_num + 1, slave_line_content)
    except Exception as e:
        pass


if __name__ == '__main__':
    main()
    